<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Easy Window Dragging (requires XP/2k/NT)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Easy Window Dragging (requires XP/2k/NT)</h1>

<p>Normally, a window can only be dragged by clicking on its title bar.
 This script extends that so that any point inside a window can be dragged.
 To activate this mode, hold down CapsLock or the middle mouse button while
 clicking, then drag the window to a new position.
</p>
<p><a href="EasyWindowDrag.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>

<pre class="NoIndent"><em>; Note: You can optionally release Capslock or the middle mouse button after
; pressing down the mouse button rather than holding it down the whole time.
; This script requires v1.0.25+.</em>

~MButton &amp; LButton::
CapsLock &amp; LButton::
CoordMode, Mouse  <em>; Switch to screen/absolute coordinates.</em>
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin% 
if EWD_WinState = 0  <em>; Only if the window isn't maximized</em>
    SetTimer, EWD_WatchMouse, 10 <em>; Track the mouse as the user drags it.</em>
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U  <em>; Button has been released, so drag is complete.</em>
{
    SetTimer, EWD_WatchMouse, off
    return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D  <em>; Escape has been pressed, so drag is cancelled.</em>
{
    SetTimer, EWD_WatchMouse, off
    WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
    return
}
<em>; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:</em>
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1   <em>; Makes the below move faster/smoother.</em>
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX  <em>; Update for the next timer-call to this subroutine.</em>
EWD_MouseStartY := EWD_MouseY
return
</pre>
</body>
</html>
